/*
    Project Milestone 3
    by Lorenzo Miori [Lorenzo.Miori@stud-inf.unibz.it,
    Matteo Angriman [Matteo.Angriman@stud-inf.unibz.it],
    Nick Preda [Nicolae.Preda@stud-inf.unibz.it]
*/

package GUI;

import DB.ExtraServiceDB;
import java.util.HashMap;

/**
 *
 * @author Nick
 */
public class ManageExtraServiceGUI extends BasicManageGUI {

    /**
     * Creates new form ManageGuestRoomGUI
     */
    public ManageExtraServiceGUI(DataModifiedListener changeListener, HashMap<String, String> defaultEntry) {
        super(changeListener, defaultEntry);
        initComponents();
        mainAreaPanel.add(fieldPanel);
        fillDataFields();
        setTitle("Extraservice Entry", "Edit extra service entry");
        finalSetup();
    }
    
    @Override
    protected void refreshCurrentData() {
        HashMap<String, String> currentEntry = getCurrentData();
        if (currentEntry == null) {
            //Create a fresh entry
            currentEntry = new HashMap<String, String>();
        }
        /* ID stays the same */
        //currentEntry.put(ExtraServiceDB.ADDRESS_STREET, streetTextField.getText());
        //currentEntry.put(ExtraServiceDB.ADDRESS_CITY, cityTextField.getText());
        //currentEntry.put(ExtraServiceDB.ADDRESS_CIVIC_N, civicNoTextField.getText());
        //currentEntry.put(ExtraServiceDB.ADDRESS_STATE, stateTextField.getText());
        //currentEntry.put(ExtraServiceDB.ADDRESS_ZIPCODE, zipcodeField.getText());

    }
    
    private void fillDataFields() {
        /* NOTE: if this is a new entry, value may be null!! */
        HashMap<String, String> currentEntry = getCurrentData();
        if (currentEntry != null) {
            uniqueIDLabel.setText("ID: "+nullSentinel(currentEntry.get(ExtraServiceDB.EXTRASERVICE_ID)));
            descriptionField.setText(nullSentinel(currentEntry.get(ExtraServiceDB.EXTRASERVICE_DESCRIPTION)));
            availableGroup.clearSelection();
            try {
                costField.setValue(Float.parseFloat(nullSentinel(currentEntry.get(ExtraServiceDB.EXTRASERVICE_COST))));
            }
            catch (Exception e) {
                costField.setValue(0);
            }
            switch (nullSentinelBoolean(currentEntry.get(ExtraServiceDB.EXTRASERVICE_AVAILABILITY))) {
                case 't':
                    availableButton.setSelected(true);
                    break;
                case 'f':
                    notAvailableButton.setSelected(true);
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        availableGroup = new javax.swing.ButtonGroup();
        fieldPanel = new javax.swing.JPanel();
        uniqueIDLabel = new javax.swing.JLabel();
        label5 = new java.awt.Label();
        label6 = new java.awt.Label();
        availableButton = new javax.swing.JRadioButton();
        notAvailableButton = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        descriptionField = new javax.swing.JTextArea();
        costField = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        uniqueIDLabel.setText("ID: ?");

        label5.setFont(new java.awt.Font("Dialog", 1, 12)); // NOI18N
        label5.setText("Cost");

        label6.setFont(new java.awt.Font("Dialog", 1, 12)); // NOI18N
        label6.setText("Availability");

        availableGroup.add(availableButton);
        availableButton.setText("Available");
        availableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                availableButtonActionPerformed(evt);
            }
        });

        availableGroup.add(notAvailableButton);
        notAvailableButton.setText("Not Available");
        notAvailableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notAvailableButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Service description"));

        descriptionField.setColumns(20);
        descriptionField.setRows(5);
        descriptionField.setTabSize(4);
        jScrollPane1.setViewportView(descriptionField);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
        );

        costField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getCurrencyInstance())));

        javax.swing.GroupLayout fieldPanelLayout = new javax.swing.GroupLayout(fieldPanel);
        fieldPanel.setLayout(fieldPanelLayout);
        fieldPanelLayout.setHorizontalGroup(
            fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(uniqueIDLabel)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(fieldPanelLayout.createSequentialGroup()
                        .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(availableButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(costField))
                        .addGap(18, 18, 18)
                        .addComponent(notAvailableButton)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        fieldPanelLayout.setVerticalGroup(
            fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fieldPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(uniqueIDLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(costField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(fieldPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(availableButton)
                        .addComponent(notAvailableButton))
                    .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 133, Short.MAX_VALUE)
                .addComponent(fieldPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 212, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .addComponent(fieldPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void availableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_availableButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_availableButtonActionPerformed

    private void notAvailableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notAvailableButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_notAvailableButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton availableButton;
    private javax.swing.ButtonGroup availableGroup;
    private javax.swing.JFormattedTextField costField;
    private javax.swing.JTextArea descriptionField;
    private javax.swing.JPanel fieldPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private java.awt.Label label5;
    private java.awt.Label label6;
    private javax.swing.JRadioButton notAvailableButton;
    private javax.swing.JLabel uniqueIDLabel;
    // End of variables declaration//GEN-END:variables

}
